home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / p2c / support / p2c.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  13.8 KB  |  531 lines  |  [TEXT/MPS ]

  1. #ifndef P2C_H
  2. #define P2C_H
  3.  
  4.  
  5. /* Header file for code generated by "p2c", the Pascal-to-C translator */
  6.  
  7. /* "p2c"  Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation.
  8.  * By Dave Gillespie, daveg@synaptics.com.  Version 1.21alpha-08.Nov.93.
  9.  * This file may be copied, modified, etc. in any way.  It is not restricted
  10.  * by the licence agreement accompanying p2c itself.
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15.  
  16.  
  17.  
  18. /* If the following heuristic fails, compile -DBSD=0 for non-BSD systems,
  19.    or -DBSD=1 for BSD systems. */
  20.  
  21. #ifdef M_XENIX
  22. # define BSD 0
  23. #endif
  24.  
  25. #ifdef vms
  26. # define BSD 0
  27. # ifndef __STDC__
  28. #  define __STDC__ 1
  29. # endif
  30. #endif
  31.  
  32. #ifdef __TURBOC__
  33. # define MSDOS 1
  34. #endif
  35.  
  36. #ifdef MSDOS
  37. # define BSD 0
  38. #endif
  39.  
  40. #ifdef FILE       /* a #define in BSD, a typedef in SYSV (hp-ux, at least) */
  41. # ifndef BSD      /*  (a convenient, but horrible kludge!) */
  42. #  define BSD 1
  43. # endif
  44. #endif
  45.  
  46. #ifdef BSD
  47. # if !BSD
  48. #  undef BSD
  49. # endif
  50. #endif
  51.  
  52.  
  53. #if (defined(__STDC__) && !defined(M_XENIX)) || defined(__TURBOC__)
  54. # include <stdlib.h>
  55. # include <stddef.h>
  56. # define HAS_STDLIB
  57. # if defined(vms) || defined(__TURBOC__)
  58. #  define NON_ANSI_CAT
  59. # endif
  60. #else
  61. # ifndef BSD
  62. #  ifndef __TURBOC__
  63. #   include <memory.h>
  64. #  endif
  65. # endif
  66. # ifdef hpux
  67. #  ifdef _INCLUDE__STDC__
  68. #   include <stddef.h>
  69. #   include <stdlib.h>
  70. #   define HAS_STDLIB
  71. #  endif
  72. # endif
  73. # include <sys/types.h>
  74. # if !defined(MSDOS) || defined(__TURBOC__)
  75. #  define NON_ANSI_CAT
  76. # endif
  77. #endif
  78.  
  79. #if defined(NON_ANSI_CAT) && !defined(ANSI_CAT)
  80. # ifdef NON_ANSI_CAT_ALTERNATE
  81. #  define __CAT__(a,b)a/**/b
  82. # else
  83. #  define __ID__(a)a
  84. #  define __CAT__(a,b)__ID__(a)b
  85. # endif
  86. #else
  87. # define __CAT__(a,b)a##b
  88. #endif
  89.  
  90.  
  91. #ifdef BSD
  92. # include <strings.h>
  93. # define memcpy(a,b,n) (bcopy(b,a,n),a)
  94. # define memcmp(a,b,n) bcmp(a,b,n)
  95. # define strchr(s,c) index(s,c)
  96. # define strrchr(s,c) rindex(s,c)
  97. #else
  98. # include <string.h>
  99. #endif
  100.  
  101. #include <ctype.h>
  102. #include <math.h>
  103. #include <setjmp.h>
  104. #include <assert.h>
  105.  
  106.  
  107. #ifndef NO_LACK
  108. #ifdef vms
  109.  
  110. #define LACK_LABS
  111. #define LACK_MEMMOVE
  112. #define LACK_MEMCPY
  113.  
  114. #else
  115.  
  116. #define LACK_LABS       /* Undefine these if your library has these */
  117. #define LACK_MEMMOVE
  118.  
  119. #endif
  120. #endif
  121.  
  122.  
  123. typedef struct __p2c_jmp_buf {
  124.     struct __p2c_jmp_buf *next;
  125.     jmp_buf jbuf;
  126. } __p2c_jmp_buf;
  127.  
  128.  
  129. /* Warning: The following will not work if setjmp is used simultaneously.
  130.    This also violates the ANSI restriction about using vars after longjmp,
  131.    but a typical implementation of longjmp will get it right anyway. */
  132.  
  133. #ifndef FAKE_TRY
  134. # define TRY(x)         do { __p2c_jmp_buf __try_jb;  \
  135.                  __try_jb.next = __top_jb;  \
  136.                  if (!setjmp((__top_jb = &__try_jb)->jbuf)) {
  137. # define RECOVER(x)    __top_jb = __try_jb.next; } else {
  138. # define RECOVER2(x,L)  __top_jb = __try_jb.next; } else {  \
  139.                  if (0) { L: __top_jb = __try_jb.next; }
  140. # define ENDTRY(x)      } } while (0) 
  141. #else
  142. # define TRY(x)         if (1) {
  143. # define RECOVER(x)     } else do {
  144. # define RECOVER2(x,L)  } else do { L: ;
  145. # define ENDTRY(x)      } while (0)
  146. #endif
  147.  
  148.  
  149.  
  150. #ifdef M_XENIX  /* avoid compiler bug */
  151. # define SHORT_MAX  (32767)
  152. # define SHORT_MIN  (-32768)
  153. #endif
  154.  
  155.  
  156. /* The following definitions work only on twos-complement machines */
  157. #ifndef SHORT_MAX
  158. # define SHORT_MAX  ((short)(((unsigned short) -1) >> 1))
  159. # define SHORT_MIN  (~SHORT_MAX)
  160. #endif
  161.  
  162. #ifndef INT_MAX
  163. # define INT_MAX    ((int)(((unsigned int) -1) >> 1))
  164. # define INT_MIN    (~INT_MAX)
  165. #endif
  166.  
  167. #ifndef LONG_MAX
  168. # define LONG_MAX   ((long)(((unsigned long) -1) >> 1))
  169. # define LONG_MIN   (~LONG_MAX)
  170. #endif
  171.  
  172. #ifndef SEEK_SET
  173. # define SEEK_SET   0
  174. # define SEEK_CUR   1
  175. # define SEEK_END   2
  176. #endif
  177.  
  178. #ifndef EXIT_SUCCESS
  179. # ifdef vms
  180. #  define EXIT_SUCCESS  1
  181. #  define EXIT_FAILURE  (02000000000L)
  182. # else
  183. #  define EXIT_SUCCESS  0
  184. #  define EXIT_FAILURE  1
  185. # endif
  186. #endif
  187.  
  188.  
  189. #define SETBITS  32
  190.  
  191.  
  192. #if defined(__STDC__) || defined(__TURBOC__)
  193. # if !defined(vms) && !defined(M_LINT)
  194. #  define Signed    signed
  195. # else
  196. #  define Signed
  197. # endif
  198. # define Void       void      /* Void f() = procedure */
  199. # ifndef Const
  200. #  define Const     const
  201. # endif
  202. # ifndef Volatile
  203. # define Volatile   volatile
  204. # endif
  205. # ifdef M_LINT
  206. #  define PP(x)     ()
  207. #  define PV()        ()
  208. typedef char *Anyptr;
  209. # else
  210. #  define PP(x)     x         /* function prototype */
  211. #  define PV()      (void)    /* null function prototype */
  212. typedef void *Anyptr;
  213. # endif
  214. #else
  215. # define Signed
  216. # define Void       void
  217. # ifndef Const
  218. #  define Const
  219. # endif
  220. # ifndef Volatile
  221. #  define Volatile
  222. # endif
  223. # define PP(x)      ()
  224. # define PV()       ()
  225. typedef char *Anyptr;
  226. #endif
  227.  
  228. #ifdef __GNUC__
  229. # define Inline     inline
  230. #else
  231. # define Inline
  232. #endif
  233.  
  234. #define Register    register  /* Register variables */
  235. #define Char        char      /* Characters (not bytes) */
  236.  
  237. #ifndef Static
  238. # define Static     static    /* Private global funcs and vars */
  239. #endif
  240.  
  241. #ifndef Local
  242. # define Local      static    /* Nested functions */
  243. #endif
  244.  
  245. typedef Signed   char schar;
  246. typedef unsigned char uchar;
  247. typedef unsigned char boolean;
  248.  
  249. #ifndef NO_DECLARE_ALFA
  250. typedef Char alfa[10];
  251. #endif
  252.  
  253. #ifndef true
  254. # define true    1
  255. # define false   0
  256. #endif
  257.  
  258. #ifndef TRUE
  259. # define TRUE    1
  260. # define FALSE   0
  261. #endif
  262.  
  263.  
  264. typedef struct {
  265.     Anyptr proc, link;
  266. } _PROCEDURE;
  267.  
  268. #ifndef _FNSIZE
  269. # define _FNSIZE  120
  270. #endif
  271.  
  272.  
  273. extern Void    PASCAL_MAIN  PP( (int, Char **) );
  274. extern Char    **P_argv;
  275. extern int     P_argc;
  276. extern short   P_escapecode;
  277. extern int     P_ioresult;
  278. extern __p2c_jmp_buf *__top_jb;
  279.  
  280.  
  281. #ifdef P2C_H_PROTO   /* if you have Ansi C but non-prototyped header files */
  282. extern Char    *strcat      PP( (Char *, Const Char *) );
  283. extern Char    *strchr      PP( (Const Char *, int) );
  284. extern int      strcmp      PP( (Const Char *, Const Char *) );
  285. extern Char    *strcpy      PP( (Char *, Const Char *) );
  286. extern size_t   strlen      PP( (Const Char *) );
  287. extern Char    *strncat     PP( (Char *, Const Char *, size_t) );
  288. extern int      strncmp     PP( (Const Char *, Const Char *, size_t) );
  289. extern Char    *strncpy     PP( (Char *, Const Char *, size_t) );
  290. extern Char    *strrchr     PP( (Const Char *, int) );
  291.  
  292. extern Anyptr   memchr      PP( (Const Anyptr, int, size_t) );
  293. extern Anyptr   memmove     PP( (Anyptr, Const Anyptr, size_t) );
  294. extern Anyptr   memset      PP( (Anyptr, int, size_t) );
  295. #ifndef memcpy
  296. extern Anyptr   memcpy      PP( (Anyptr, Const Anyptr, size_t) );
  297. extern int      memcmp      PP( (Const Anyptr, Const Anyptr, size_t) );
  298. #endif
  299.  
  300. extern int      atoi        PP( (Const Char *) );
  301. extern double   atof        PP( (Const Char *) );
  302. extern long     atol        PP( (Const Char *) );
  303. extern double   strtod      PP( (Const Char *, Char **) );
  304. extern long     strtol      PP( (Const Char *, Char **, int) );
  305. #endif /*P2C_H_PROTO*/
  306.  
  307. #ifndef HAS_STDLIB
  308. #ifndef NO_DECLARE_MALLOC
  309. extern Anyptr   malloc      PP( (size_t) );
  310. extern Void     free        PP( (Anyptr) );
  311. #endif
  312. #endif
  313.  
  314. extern int      _OutMem     PV();
  315. extern int      _CaseCheck  PV();
  316. extern int      _NilCheck   PV();
  317. extern int    _Escape     PP( (int) );
  318. extern int    _EscIO      PP( (int) );
  319. extern int    _EscIO2     PP( (int, Char *) );
  320.  
  321. extern long     ipow        PP( (long, long) );
  322. extern long     P_imax      PP( (long, long) );
  323. extern long     P_imin      PP( (long, long) );
  324. extern double   P_rmax      PP( (double, double) );
  325. extern double   P_rmin      PP( (double, double) );
  326. extern Char    *strsub      PP( (Char *, Char *, int, int) );
  327. extern Char    *strltrim    PP( (Char *) );
  328. extern Char    *strrtrim    PP( (Char *) );
  329. extern Char    *strrpt      PP( (Char *, Char *, int) );
  330. extern Char    *strpad      PP( (Char *, Char *, int, int) );
  331. extern int      strpos2     PP( (Char *, Char *, int) );
  332. extern long     memavail    PV();
  333. extern int      P_peek      PP( (FILE *) );
  334. extern int      P_eof       PP( (FILE *) );
  335. extern int      P_eoln      PP( (FILE *) );
  336. extern Void     P_readpaoc  PP( (FILE *, Char *, int) );
  337. extern Void     P_readlnpaoc PP( (FILE *, Char *, int) );
  338. extern long     P_maxpos    PP( (FILE *) );
  339. extern Char    *P_trimname  PP( (Char *, int) );
  340. extern long    *P_setunion  PP( (long *, long *, long *) );
  341. extern long    *P_setint    PP( (long *, long *, long *) );
  342. extern long    *P_setdiff   PP( (long *, long *, long *) );
  343. extern long    *P_setxor    PP( (long *, long *, long *) );
  344. extern int      P_inset     PP( (unsigned, long *) );
  345. extern int      P_setequal  PP( (long *, long *) );
  346. extern int      P_subset    PP( (long *, long *) );
  347. extern long    *P_addset    PP( (long *, unsigned) );
  348. extern long    *P_addsetr   PP( (long *, unsigned, unsigned) );
  349. extern long    *P_remset    PP( (long *, unsigned) );
  350. extern long    *P_setcpy    PP( (long *, long *) );
  351. extern long    *P_expset    PP( (long *, long) );
  352. extern long     P_packset   PP( (long *) );
  353. extern int      P_getcmdline PP( (int, int, Char *) );
  354. extern Void     TimeStamp   PP( (int *, int *, int *,
  355.                  int *, int *, int *) );
  356. extern Void    P_sun_argv  PP( (char *, int, int) );
  357. extern FILE    *_skipspaces PP( (FILE *) );
  358. extern FILE    *_skipnlspaces PP( (FILE *) );
  359.  
  360.  
  361. /* I/O error handling */
  362. #define _CHKIO(cond,ior,val,def)  ((cond) ? P_ioresult=0,(val)  \
  363.                       : P_ioresult=(ior),(def))
  364. #define _SETIO(cond,ior)          (P_ioresult = (cond) ? 0 : (ior))
  365.  
  366. /* Following defines are suitable for the HP Pascal operating system */
  367. #define FileNotFound     10
  368. #define FileNotOpen      13
  369. #define FileWriteError   38
  370. #define BadInputFormat   14
  371. #define EndOfFile        30
  372.  
  373. #define FILENOTFOUND     10
  374. #define FILENOTOPEN      13
  375. #define FILEWRITEERROR   38
  376. #define BADINPUTFORMAT   14
  377. #define ENDOFFILE        30
  378.  
  379. /* Creating temporary files */
  380. #if (defined(BSD) || defined(NO_TMPFILE)) && !defined(HAVE_TMPFILE)
  381. # define tmpfile()  (fopen(tmpnam(NULL), "w+"))
  382. #endif
  383.  
  384. /* File buffers */
  385. #define FILEBUF(f,sc,type) sc int __CAT__(f,_BFLAGS);   \
  386.                sc type __CAT__(f,_BUFFER)
  387. #define FILEBUFNC(f,type)  int __CAT__(f,_BFLAGS);   \
  388.                type __CAT__(f,_BUFFER)
  389.  
  390. #define RESETBUF(f,type)   (__CAT__(f,_BFLAGS) = 1)
  391. #define SETUPBUF(f,type)   (__CAT__(f,_BFLAGS) = 0)
  392.  
  393. #define GETFBUF(f,type)    (*((__CAT__(f,_BFLAGS) == 1 &&   \
  394.                    ((__CAT__(f,_BFLAGS) = 2),   \
  395.                 fread(&__CAT__(f,_BUFFER),  \
  396.                       sizeof(type),1,(f)))),\
  397.                   &__CAT__(f,_BUFFER)))
  398. #define AGETFBUF(f,type)   ((__CAT__(f,_BFLAGS) == 1 &&   \
  399.                  ((__CAT__(f,_BFLAGS) = 2),   \
  400.                   fread(__CAT__(f,_BUFFER),  \
  401.                     sizeof(type),1,(f)))),\
  402.                 __CAT__(f,_BUFFER))
  403.  
  404. #define PUTFBUF(f,type,v)  (GETFBUF(f,type) = (v))
  405. #define CPUTFBUF(f,v)      (PUTFBUF(f,char,v))
  406. #define APUTFBUF(f,type,v) (memcpy(AGETFBUF(f,type), (v),  \
  407.                    sizeof(__CAT__(f,_BUFFER))))
  408.  
  409. #define GET(f,type)        (__CAT__(f,_BFLAGS) == 1 ?   \
  410.                 fread(&__CAT__(f,_BUFFER),sizeof(type),1,(f)) :  \
  411.                 (__CAT__(f,_BFLAGS) = 1))
  412.  
  413. #define PUT(f,type)        (fwrite(&__CAT__(f,_BUFFER),sizeof(type),1,(f)),  \
  414.                 (__CAT__(f,_BFLAGS) = 0))
  415. #define CPUT(f)            (PUT(f,char))
  416.  
  417. #define BUFEOF(f)       (__CAT__(f,_BFLAGS) != 2 && P_eof(f))
  418. #define BUFFPOS(f)       (ftell(f) - (__CAT__(f,_BFLAGS) == 2))
  419.  
  420. typedef struct {
  421.     FILE *f;
  422.     FILEBUFNC(f,Char);
  423.     Char name[_FNSIZE];
  424. } _TEXT;
  425.  
  426. /* Memory allocation */
  427. #ifdef __GCC__
  428. # define Malloc(n)  (malloc(n) ?: (Anyptr)_OutMem())
  429. #else
  430. extern Anyptr __MallocTemp__;
  431. # define Malloc(n)  ((__MallocTemp__ = malloc(n)) ? __MallocTemp__ : (Anyptr)_OutMem())
  432. #endif
  433. #define FreeR(p)    (free((Anyptr)(p)))    /* used if arg is an rvalue */
  434. #define Free(p)     (free((Anyptr)(p)), (p)=NULL)
  435.  
  436. /* sign extension */
  437. #define SEXT(x,n)   ((x) | -(((x) & (1L<<((n)-1))) << 1))
  438.  
  439. /* packed arrays */   /* BEWARE: these are untested! */
  440. #define P_getbits_UB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] >>   \
  441.                        (((~(i))&((1<<(L)-(n))-1)) << (n)) &  \
  442.                        (1<<(1<<(n)))-1))
  443.  
  444. #define P_getbits_SB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] <<   \
  445.                        (16 - ((((~(i))&((1<<(L)-(n))-1))+1) <<\
  446.                           (n)) >> (16-(1<<(n))))))
  447.  
  448. #define P_putbits_UB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
  449.                  (x) << (((~(i))&((1<<(L)-(n))-1)) << (n)))
  450.  
  451. #define P_putbits_SB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
  452.                  ((x) & (1<<(1<<(n)))-1) <<   \
  453.                  (((~(i))&((1<<(L)-(n))-1)) << (n)))
  454.  
  455. #define P_clrbits_B(a,i,n,L)    ((a)[(i)>>(L)-(n)] &=   \
  456.                  ~( ((1<<(1<<(n)))-1) <<   \
  457.                    (((~(i))&((1<<(L)-(n))-1)) << (n))) )
  458.  
  459. /* small packed arrays */
  460. #define P_getbits_US(v,i,n)     ((int)((v) >> ((i)<<(n)) & (1<<(1<<(n)))-1))
  461. #define P_getbits_SS(v,i,n)     ((int)((long)(v) << (SETBITS - (((i)+1) << (n))) >> (SETBITS-(1<<(n)))))
  462. #define P_putbits_US(v,i,x,n)   ((v) |= (x) << ((i) << (n)))
  463. #define P_putbits_SS(v,i,x,n)   ((v) |= ((x) & (1<<(1<<(n)))-1) << ((i)<<(n)))
  464. #define P_clrbits_S(v,i,n)      ((v) &= ~( ((1<<(1<<(n)))-1) << ((i)<<(n)) ))
  465.  
  466. #define P_max(a,b)   ((a) > (b) ? (a) : (b))
  467. #define P_min(a,b)   ((a) < (b) ? (a) : (b))
  468.  
  469.  
  470. /* Fix ANSI-isms */
  471.  
  472. #ifdef LACK_LABS
  473. # ifndef labs
  474. #  define labs  my_labs
  475.    extern long my_labs PP( (long) );
  476. # endif
  477. #endif
  478.  
  479. #ifdef LACK_MEMMOVE
  480. # ifndef memmove
  481. #  define memmove  my_memmove
  482.    extern Anyptr my_memmove PP( (Anyptr, Const Anyptr, size_t) );
  483. # endif
  484. #endif
  485.  
  486. #ifdef LACK_MEMCPY
  487. # ifndef memcpy
  488. #  define memcpy  my_memcpy
  489.    extern Anyptr my_memcpy PP( (Anyptr, Const Anyptr, size_t) );
  490. # endif
  491. # ifndef memcmp
  492. #  define memcmp  my_memcmp
  493.    extern int my_memcmp PP( (Const Anyptr, Const Anyptr, size_t) );
  494. # endif
  495. # ifndef memset
  496. #  define memset  my_memset
  497.    extern Anyptr my_memset PP( (Anyptr, int, size_t) );
  498. # endif
  499. #endif
  500.  
  501. /* Fix toupper/tolower on Suns and other stupid BSD systems */
  502. #ifdef toupper
  503. # undef toupper
  504. # undef tolower
  505. # define toupper(c)   my_toupper(c)
  506. # define tolower(c)   my_tolower(c)
  507. #endif
  508.  
  509. #ifndef _toupper
  510. # if 'A' == 65 && 'a' == 97
  511. #  define _toupper(c)  ((c)-'a'+'A')
  512. #  define _tolower(c)  ((c)-'A'+'a')
  513. # else
  514. #  ifdef toupper
  515. #   undef toupper   /* hope these are shadowing real functions, */
  516. #   undef tolower   /* because my_toupper calls _toupper! */
  517. #  endif
  518. #  define _toupper(c)  toupper(c)
  519. #  define _tolower(c)  tolower(c)
  520. # endif
  521. #endif
  522.  
  523.  
  524. #endif    /* P2C_H */
  525.  
  526.  
  527.  
  528. /* End. */
  529.  
  530.  
  531.